﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Security.Cryptography;
using System.Text;

namespace Bus_proj.website
{
    public partial class change_pass_user : System.Web.UI.Page
    {
        public static string getMd5Hash(string input)
        {
            MD5 md5Hasher = MD5.Create();
            byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
            StringBuilder sBuilder = new StringBuilder();

            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }
            return sBuilder.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            string Connection = ConfigurationManager.ConnectionStrings["Bus_proConnectionString"].ConnectionString;            
            string ticket2 = @"select *
                               from Table_payment";
            SqlCommand sqlcomm2 = new SqlCommand();
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da_ticket2 = new SqlDataAdapter(ticket2, sqlconn);
            DataTable dt_ticket2 = new DataTable();
            da_ticket2.Fill(dt_ticket2);
            if (dt_ticket2.Rows.Count <= 0)
            {
                ;

            }
            else
            {
                for (int i = 0; i < dt_ticket2.Rows.Count; i++)
                {
                    string aa = getMd5Hash(dt_ticket2.Rows[i]["payment_id"].ToString());
                    int bb = Int32.Parse(dt_ticket2.Rows[i]["payment_no"].ToString());
                    var q = from p in db.Table_payments
                            where p.payment_no == bb
                            select p;
                    q.ToList().ForEach(c => c.encode = aa);
                    db.SubmitChanges();
                
                    
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            ModalPopupExtender1.Show();
        }
    }
}